package com.ihome.android.academy;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ihome.android.EAActivity;
import com.ihome.android.annotation.EAInjectView;
import com.ihome.android.academy.R;
import com.ihome.android.util.ImageHelper;
import com.ihome.android.util.Util;

public class HelpActivity extends EAActivity {

	private String			TAG	= HelpActivity.class.getSimpleName();

	@EAInjectView(id = R.id.tv_title)
	private TextView		tv_title;
	@EAInjectView(id = R.id.helpinfo)
	private TextView		helpinfo;
	@EAInjectView(id = R.id.ll_help)
	private LinearLayout	ll_help;
	@EAInjectView(id = R.id.iv_inverted)
	private ImageView		iv_inverted;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.help);

		tv_title.setOnClickListener(new TextView.OnClickListener() {

			@Override
			public void onClick(View v) {
				HelpActivity.this.finish();
			}
		});
		helpinfo.setText(getString(R.string.helpinfo, Util.getAPKVersion(HelpActivity.this)));

		ViewTreeObserver vto = ll_help.getViewTreeObserver();
		vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
			@Override
			public void onGlobalLayout() {

				if (ll_help.getWidth() > 0 && ll_help.getHeight() > 0) {
					ll_help.getViewTreeObserver().removeGlobalOnLayoutListener(this);
					updateShadow(ll_help, iv_inverted);
				}
			}
		});
	}

	private void updateShadow(View view, ImageView imageView) {
		if (view.getWidth() < 1 || view.getHeight() < 1) {
			return;
		}
		Bitmap mShadowBitmap = ImageHelper.createReflectedImage(view, Util.convertDIP2PX(getApplicationContext(), 80), -65);
		imageView.setImageBitmap(mShadowBitmap);
	}
}
